<template>
  <div class="update-birthday">
    <van-datetime-picker
      v-model="localBirthday"
      type="date"
      title="选择生日日期"
      @cancel="$emit('close')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user.js'
import * as dayjs from 'dayjs'
export default {
  name: 'UpdateBirthday',
  props: {
    value: {
      type: String,
      required: true
    }
  },
  components: {},
  data () {
    return {
      localBirthday: new Date(this.value)
    }
  },
  computed: {},
  watch: {},
  methods: {
    async onConfirm (value) {
      // const birthday = `${this.localBirthday.getFullYear()}-${this.localBirthday.getMonth() + 1}-${this.localBirthday.getDate()}`
      const birthday = dayjs(this.localBirthday).format('YYYY-MM-DD')
      await updateUserProfile({
        birthday: birthday
      })
      this.$emit('input', birthday)
      this.$emit('close')
      this.$toast.success('修改生日成功')
    }
  },
  created () {
  },
  mounted () {
  },
  destroyed () {
  }
}
</script>

<style scoped lang='less'>
</style>
